package com.ovidiojf.siesec.classe;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class ClasseDAOHibernate implements ClasseDAO {
	
	private Session session;
	
	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

	@Override
	public void salvar(Classe classe) {
		this.session.save(classe);
	}

	@Override
	public void excluir(Classe classe) {
		this.session.delete(classe);
	}

	@Override
	public void alterar(Classe classe) {
		this.session.update(classe);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Classe> listar() {
		return this.session.createCriteria(Classe.class).list();
	}

	@Override
	public Classe pesquisarPorId(String id) {
		Criteria criteria = this.session.createCriteria(Classe.class);
		criteria.add(Restrictions.eq("id", id));
		return (Classe) criteria.uniqueResult();
	}

	@Override
	public Classe pesquisarPorNumeroPRODESP(String numeroPRODESP) {
		Criteria criteria = this.session.createCriteria(Classe.class);
		criteria.add(Restrictions.eq("numeroPRODESP", numeroPRODESP));
		return (Classe) criteria.uniqueResult();
	}

}
